<template>
  <div>
    <Card title="新增税类"
          :bordered="false"
          dis-hover
          class="ivu-mt">
      <Form ref="brandForm"
            :model="taxCateFormData"
            :rules="taxCateFormRules"
            :label-width="140">
        <Row>
          <Col span="18"
               offset="3">
          <FormItem label="税率名称："
                    prop="taxCateName">
            <Input v-model="taxCateFormData.taxCateName"
                   maxlength="20"
                   show-word-limit
                   placeholder="请输入归类名称"></Input>
          </FormItem>
          </Col>
          <Col span="18"
               offset="3">
          <FormItem label="税类编号："
                    prop="taxCateNo">
            <Input v-model="taxCateFormData.taxCateNo"
                   maxlength="20"
                   show-word-limit
                   placeholder="请输入税类编号"></Input>
          </FormItem>
          </Col>
          <Col span="18"
               offset="3">
          <FormItem label="税率："
                    prop="taxRate">
            <Input v-model="taxCateFormData.taxRate"
                   maxlength="20"
                   show-word-limit
                   placeholder="请输入税率"></Input>
          </FormItem>
          </Col>
          <Col span="18"
               offset="3">
          <FormItem>
            <Button type="primary"
                    @click="handleSubmit(taxCateFormData)">提交</Button>
            <Button @click="handleReset('brandForm')"
                    class="ivu-ml-8">取消</Button>
          </FormItem>
          </Col>
        </Row>
      </Form>
    </Card>
  </div>
</template>
<script>
import Upload from '@/components/common/upload'; // 上传组件

import {
  ApiRequest
} from '@api/basePage';

export default {
  components: {
    Upload
  },
  data () {
    return {
      taxCateFormData: {
        taxCateName: "",
        taxCateNo: "",
        taxRate: "",
      },
      requestApi: { // 视情况自定义
        // 新增品牌
        taxcategoryAdd: {
          url: '/sysback/taxcategory/baseAdd', // 接口地址
          type: 'post' // 接口请求类型
        }
      },
      taxCateFormRules: {
        taxCateName: [{
          required: true,
          message: '请填写税率名称',
          trigger: 'blur'
        },
        {
          type: 'string',
          min: 1,
          message: '税率名称不得少于一个字符',
          trigger: 'blur'
        },

        ],
        taxCateNo: [{
          required: true,
          message: '请填写税类编号',
          trigger: 'blur'
        },
        {
          type: 'string',
          min: 1,
          message: '税类编号不得少于一个字符',
          trigger: 'blur'
        },
        ],
        taxRate: [{
          required: true,
          message: '请填写税率',
          trigger: 'blur'
        },
        ],
      },
    }
  },
  methods: {
    // 清空表单
    handleReset (name) {
      this.$router.go(-1)
    },
    maxTagPlaceholder (num) {
      return 'more ' + num;
    },
    handleSubmit (formData) {
        let data = {
        taxCateName: formData.taxCateName,
        taxCateNo: formData.taxCateNo,
        taxRate: parseFloat(formData.taxRate),
        departmentUuid:"",
        userUuid:""
      }
      // 开始请求列表
      ApiRequest(this.requestApi.taxcategoryAdd.url, this.requestApi.taxcategoryAdd.type, data, false).then(res => {
        if (res.retStatus === '1') {
          this.$Message.success('新增税类成功');
          this.$router.go(-1);
        }
      })
    },
  }
}
</script>
<style lang="less" scoped>
</style>
